package com.zhao.fannews.units;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhao.fannews.R;
import com.zhao.fannews.domain.News;

import java.util.List;

/**
 * Created by Zhao on 2016/5/9.
 */
public class MyAdapter extends ArrayAdapter<News> {
    private int resource;
    private Context context;
    private List<News> newsList;

    public MyAdapter(Context context, int resource, List<News> objects) {
        super(context, resource, objects);
        this.resource = resource;
        this.context = context;
        this.newsList=objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(resource, null);
        TextView tv_description = (TextView) view.findViewById(R.id.tv_description);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        ImageView iv_news = (ImageView)view.findViewById(R.id.iv_news);
        News news = newsList.get(position);
        tv_description.setText(news.getDescription());
        tv_title.setText(news.getTitle());
        iv_news.setImageBitmap(news.getImage());
        return view;
    }
}
